<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('AdminClass/index')}">班别管理</a></li>
        <li><a href="{:url('AdminClass/add')}">添加班别</a></li>
    </ul>   

    <form method="post" class="js-ajax-form" action="{:url('AdminClass/listOrder')}">
        <div class="table-actions">
            <button type="submit" class="btn btn-primary btn-sm js-ajax-submit">{:lang('SORT')}</button>            
        </div>
    
        <table class="table table-hover table-bordered table-list" id="menus-table">
            <thead>
            <tr>
                <th width="16" style="padding-left:20px;"><label><input type="checkbox" class="js-check-all"
                                                                        data-direction="x"
                                                                        data-checklist="js-check-x"></label></th>
                <th width="50">排序</th>
                <th width="50">ID</th>
                <th>班别名称</th>
                <th>描述</th>               
                <th width="200">操作</th>
            </tr>
            </thead>
            <tbody>
                <foreach $list as $vo>
                <tr>
                    <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x"
                        name="ids[]" value="{$vo.id}"></td>
                    <td><input name="list_orders[{$vo.id}]" type="text" size="3" value="{$vo.list_order}"
                        class="input-order"></td>
                    <td>{$vo.id}</td>
                    <td>{$vo.name}</td>
                    <td>{$vo.description}</td>
                    <td>
                        <a href="{:url('AdminClass/edit',['id'=>$vo.id])}">编辑</a>
                        <a class="js-ajax-delete" href="{:url('AdminClass/delete',['id'=>$vo.id])}">删除</a>
                    </td>
                </tr>
                </foreach>
            </tbody>
            <tfoot>
            <tr>
                <th width="16" style="padding-left:20px;"><label><input type="checkbox" class="js-check-all"
                                                                        data-direction="x"
                                                                        data-checklist="js-check-x"></label></th>
                <th width="50">排序</th>
                <th width="50">ID</th>
                <th>班别名称</th>
                <th>描述</th>                
                <th width="200">操作</th>
            </tr>
            </tfoot>
        </table>            
        <div class="table-actions">
            <button type="submit" class="btn btn-primary btn-sm js-ajax-submit">{:lang('SORT')}</button>
        </div>
        <ul class="pagination">{$page|default=''}</ul>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    $(document).ready(function () {
        Wind.css('treeTable');
        Wind.use('treeTable', function () {
            $("#menus-table").treeTable({
                indent: 20,
                initialState: 'expanded'
            });
        });
    });

    // $(' #menus-table .js-check').change(function () {
    //     console.log('change');
    //     checkNode(this);
    // });
    //
    // function checkNode(obj) {
    //     var $obj   = $(obj);
    //     var $table = $obj.parents('table');
    //
    //     var id       = $obj.data('id');
    //     var parentId = $obj.data('parent_id');
    //
    //     function checkParent(id, parentId, checked) {
    //         console.log('checkParent:' + id);
    //         var $parent = $("tr [data-id='" + parentId + "']", $table);
    //         if ($parent.length > 0) {
    //             $parent.prop("checked", checked);
    //             checkParent($parent.data('id'), $parent.data('parent_id'), checked);
    //         }
    //     }
    //
    //     function checkChild(id, parentId, checked) {
    //         console.log('checkChild:' + id);
    //         var $child = $("tr [data-parent_id='" + id + "']", $table);
    //
    //         if ($child.length > 0) {
    //             $child.prop("checked", checked);
    //             checkChild($child.data('id'), $child.data('parent_id'), checked);
    //         }
    //     }
    //
    //     if ($obj.is(':checked')) {
    //         checkParent(id, parentId, true);
    //         checkChild(id, parentId, true);
    //     } else {
    //         checkParent(id, parentId, false);
    //         checkChild(id, parentId, false);
    //     }
    //     return;
    //     var chk   = $("input[type='checkbox']");
    //     var count = chk.length;
    //
    //     var num       = chk.index(obj);
    //     var level_top = level_bottom = chk.eq(num).attr('level');
    //     for (var i = num; i >= 0; i--) {
    //         var le = chk.eq(i).attr('level');
    //         if (le < level_top) {
    //             chk.eq(i).prop("checked", true);
    //             var level_top = level_top - 1;
    //         }
    //     }
    //     for (var j = num + 1; j < count; j++) {
    //         var le = chk.eq(j).attr('level');
    //         if (chk.eq(num).prop("checked")) {
    //
    //             if (le > level_bottom) {
    //                 chk.eq(j).prop("checked", true);
    //             }
    //             else if (le == level_bottom) {
    //                 break;
    //             }
    //         } else {
    //             if (le > level_bottom) {
    //                 chk.eq(j).prop("checked", false);
    //             } else if (le == level_bottom) {
    //                 break;
    //             }
    //         }
    //     }
    // }
</script>
</body>
</html>